package com.mo.config.conveter;


import com.alibaba.excel.converters.Converter;
import com.alibaba.excel.metadata.GlobalConfiguration;
import com.alibaba.excel.metadata.data.ReadCellData;
import com.alibaba.excel.metadata.property.ExcelContentProperty;
import com.mo.DlykApplication;
import com.mo.model.TDicValue;
import com.mo.result.DicEnum;

import java.util.List;

/**
 * @author mo
 * version
 */
public class AppellationConverter implements Converter<Integer> {
    /**
    *把excel中的数据转为java的数据
    */
    @Override
    public Integer convertToJavaData(ReadCellData<?> cellData, ExcelContentProperty contentProperty, GlobalConfiguration globalConfiguration) throws Exception {
        String cellAppellation = cellData.getStringValue();
        List<TDicValue> tDicValueList = (List<TDicValue>) DlykApplication.cacheMap.get(DicEnum.APPELLATION.getCode());

        for (TDicValue tDicValue : tDicValueList) {
            Integer id = tDicValue.getId();
            String name = tDicValue.getTypeValue();
            if (cellAppellation.equals(name)){
                return id;
            }
        }
        return -1;
    }
}
